package no.sachmuld.methodcombination.examples.performance;

import no.sachmuld.aspectjattach.AspectJAgent;
import no.sachmuld.methodcombination.examples.performance.annotation.FooY;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;

/**
 *
 */
public class Main implements Runnable {

    @Override
    public void run() {

        AspectJAgent.initializeIfNeeded();

        List<Step> expected = Arrays.asList(Step.values());

        Foo[] foos = {
                new no.sachmuld.methodcombination.examples.performance.adapter.FooY(),
                new Callable<Foo>() {
                    @Override
                    public Foo call()  {
                        return new FooY();
                    }
                }.call(),
                new no.sachmuld.methodcombination.examples.performance.reflection.FooY(),
                new no.sachmuld.methodcombination.examples.performance.plain.Foo()
        };

        for (Foo foo : foos) {

            //ramp-up
            {
                List<Step> actual = new ArrayList<>();
                foo.setTrace(actual);
                foo.bar(0);
            }

            int n = 1000000;
            long t0 = System.currentTimeMillis();
            for (int i = 0; i < n; i++) {
                List<Step> actual = new ArrayList<>();
                foo.setTrace(actual);
                foo.bar(0);
            }
            long t1 = System.currentTimeMillis();
            System.out.println(foo.getClass().getName() + ": " + (t1 - t0));

        }

    }

    public static void main(String... args) throws Exception {

        new Main().run();

    }

}
